package com.duowei.diandan.db.entry;

import android.arch.persistence.room.Entity;
import android.arch.persistence.room.PrimaryKey;

import com.duowei.diandan.sql.InsertField;
import com.duowei.diandan.sql.TableName;
import com.duowei.diandan.sql.UpdateField;

import org.joda.time.LocalDateTime;

import java.util.Locale;
import java.util.Objects;

/**
 * 点单临时表基本信息
 */
@TableName(name = "WMLSBJB")
@Entity
public class Wmlsbjb {
    @PrimaryKey(autoGenerate = true)
    private long id;

    /**
     * 单据编号（主键）
     * 格式： 计算机名+yyyymmddhhmmsszzz
     */
    @InsertField
    private String wmdbh; // VARCHAR(500) NOT NULL
    /** 销退标志（默认1） */
    @UpdateField
    @InsertField
    private String xtbz = "1"; // VARCHAR(2),
    /** 当前用户名称 */
    @UpdateField
    @InsertField
    private String yhbh; // VARCHAR(900),
    /**
     * 桌号
     * 格式：餐桌名称+’,’
     * 如（A101，）
     */
    @UpdateField
    @InsertField
    private String zh; // VARCHAR(900),
    /** 总计金额 */
    @UpdateField
    @InsertField
    private Float ys;      // NUMERIC(10, 2),
    /** 交易时间 */
    @UpdateField
    @InsertField
    private LocalDateTime jysj;//     DATETIME (23, 3),
    /** 是否已结帐（0未结账 1已结账） */
    @UpdateField
    @InsertField
    private String sfyjz = "0";//    VARCHAR(2),
    @UpdateField
    @InsertField
    private Float ysje; //  NUMERIC(10, 2),
    @UpdateField
    @InsertField
    private String hykh; //   VARCHAR(50),
    /** 计算机名 */
    @UpdateField
    @InsertField
    private String jsj; //   VARCHAR(300),
    @UpdateField
    @InsertField
    private String qbdb; //   VARCHAR(2),
    /** 就餐人数 */
    @UpdateField
    @InsertField
    private Float jcrs = 1f; //  NUMERIC(18),
    /** 折扣 */
    @UpdateField
    @InsertField
    private Float zk; //  NUMERIC(10, 2),
    @UpdateField
    @InsertField
    private Float zr; //  NUMERIC(10, 2),
    @UpdateField
    @InsertField
    private Float bcwnjs; //  NUMERIC(10, 2),
    @UpdateField
    @InsertField
    private Float ss; //  NUMERIC(10, 2),
    @UpdateField
    @InsertField
    private String hykdj; //   VARCHAR(50),
    @UpdateField
    @InsertField
    private String zkfs; //   VARCHAR(50),
    /** 来客类型 */
    @UpdateField
    @InsertField
    private String jcfs; //   VARCHAR(100),
    /** 备注 */
    @UpdateField
    @InsertField
    private String by1; //   VARCHAR(100),
    @UpdateField
    @InsertField
    private String by2; //   VARCHAR(100),
    @UpdateField
    @InsertField
    private Float by3; //  NUMERIC(10, 2),
    @UpdateField
    @InsertField
    private Float by4; //  NUMERIC(10, 2),
    @UpdateField
    @InsertField
    private LocalDateTime by5; //     DATETIME (23, 3),
    @UpdateField
    @InsertField
    private String jzbz; //   VARCHAR(100),
    @UpdateField
    @InsertField
    private LocalDateTime jskssj; //   DATETIME (23, 3),
    @UpdateField
    @InsertField
    private LocalDateTime jsjssj; //   DATETIME (23, 3),
    /** 单据流水号 */
    @UpdateField
    @InsertField
    private Integer djlsh; //  INT (10),
    @UpdateField
    @InsertField
    private String by6; // VARCHAR(100),
    @UpdateField
    @InsertField
    private String by7; // VARCHAR(100),
    @UpdateField
    @InsertField
    private String by8; // VARCHAR(100),
    @UpdateField
    @InsertField
    private Float by9; //NUMERIC(18, 4),
    @UpdateField
    @InsertField
    private Float by10; //NUMERIC(18, 4),
    @UpdateField
    @InsertField
    private LocalDateTime by11; //   DATETIME (23, 3),
    @UpdateField
    @InsertField
    private String sffs; // VARCHAR(30),
    /** 1开台 2点餐 */
    @UpdateField
    @InsertField
    private String by12 = "2"; // VARCHAR(50),
    /** 提交给微信、支付宝的账单号 */
    @UpdateField
    @InsertField
    private String by13; // VARCHAR(50),
    @UpdateField
    @InsertField
    private String by14; // VARCHAR(50),
    @UpdateField
    @InsertField
    private String by15; // VARCHAR(50),
    /** 支付宝返回的交易单号 */
    @UpdateField
    @InsertField
    private String by16; // VARCHAR(100),
    @UpdateField
    @InsertField
    private String by17; // VARCHAR(100),
    @UpdateField
    @InsertField
    private String by18; // VARCHAR(100),
    @UpdateField
    @InsertField
    private Float by19; //NUMERIC(18, 4),
    @UpdateField
    @InsertField
    private Float by20; //NUMERIC(18, 4),
    @UpdateField
    @InsertField
    private String order_id; // VARCHAR(20)

    public Wmlsbjb() {
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getWmdbh() {
        return wmdbh;
    }

    public void setWmdbh(String wmdbh) {
        this.wmdbh = wmdbh;
    }

    public String getXtbz() {
        return xtbz;
    }

    public void setXtbz(String xtbz) {
        this.xtbz = xtbz;
    }

    public String getYhbh() {
        return yhbh;
    }

    public void setYhbh(String yhbh) {
        this.yhbh = yhbh;
    }

    public String getZh() {
        return zh;
    }

    public void setZh(String zh) {
        this.zh = zh;
    }

    public Float getYs() {
        return ys;
    }

    public void setYs(Float ys) {
        this.ys = ys;
    }

    public LocalDateTime getJysj() {
        return jysj;
    }

    public void setJysj(LocalDateTime jysj) {
        this.jysj = jysj;
    }

    public String getSfyjz() {
        return sfyjz;
    }

    public void setSfyjz(String sfyjz) {
        this.sfyjz = sfyjz;
    }

    public Float getYsje() {
        return ysje;
    }

    public void setYsje(Float ysje) {
        this.ysje = ysje;
    }

    public String getHykh() {
        return hykh;
    }

    public void setHykh(String hykh) {
        this.hykh = hykh;
    }

    public String getJsj() {
        return jsj;
    }

    public void setJsj(String jsj) {
        this.jsj = jsj;
    }

    public String getQbdb() {
        return qbdb;
    }

    public void setQbdb(String qbdb) {
        this.qbdb = qbdb;
    }

    public Float getJcrs() {
        return jcrs;
    }

    public void setJcrs(Float jcrs) {
        this.jcrs = jcrs;
    }

    public Float getZk() {
        return zk;
    }

    public void setZk(Float zk) {
        this.zk = zk;
    }

    public Float getZr() {
        return zr;
    }

    public void setZr(Float zr) {
        this.zr = zr;
    }

    public Float getBcwnjs() {
        return bcwnjs;
    }

    public void setBcwnjs(Float bcwnjs) {
        this.bcwnjs = bcwnjs;
    }

    public Float getSs() {
        return ss;
    }

    public void setSs(Float ss) {
        this.ss = ss;
    }

    public String getHykdj() {
        return hykdj;
    }

    public void setHykdj(String hykdj) {
        this.hykdj = hykdj;
    }

    public String getZkfs() {
        return zkfs;
    }

    public void setZkfs(String zkfs) {
        this.zkfs = zkfs;
    }

    public String getJcfs() {
        return jcfs;
    }

    public void setJcfs(String jcfs) {
        this.jcfs = jcfs;
    }

    public String getBy1() {
        return by1;
    }

    public void setBy1(String by1) {
        this.by1 = by1;
    }

    public String getBy2() {
        return by2;
    }

    public void setBy2(String by2) {
        this.by2 = by2;
    }

    public Float getBy3() {
        return by3;
    }

    public void setBy3(Float by3) {
        this.by3 = by3;
    }

    public Float getBy4() {
        return by4;
    }

    public void setBy4(Float by4) {
        this.by4 = by4;
    }

    public LocalDateTime getBy5() {
        return by5;
    }

    public void setBy5(LocalDateTime by5) {
        this.by5 = by5;
    }

    public String getJzbz() {
        return jzbz;
    }

    public void setJzbz(String jzbz) {
        this.jzbz = jzbz;
    }

    public LocalDateTime getJskssj() {
        return jskssj;
    }

    public void setJskssj(LocalDateTime jskssj) {
        this.jskssj = jskssj;
    }

    public LocalDateTime getJsjssj() {
        return jsjssj;
    }

    public void setJsjssj(LocalDateTime jsjssj) {
        this.jsjssj = jsjssj;
    }

    public Integer getDjlsh() {
        return djlsh;
    }

    public void setDjlsh(Integer djlsh) {
        this.djlsh = djlsh;
    }

    public String getBy6() {
        return by6;
    }

    public void setBy6(String by6) {
        this.by6 = by6;
    }

    public String getBy7() {
        return by7;
    }

    public void setBy7(String by7) {
        this.by7 = by7;
    }

    public String getBy8() {
        return by8;
    }

    public void setBy8(String by8) {
        this.by8 = by8;
    }

    public Float getBy9() {
        return by9;
    }

    public void setBy9(Float by9) {
        this.by9 = by9;
    }

    public Float getBy10() {
        return by10;
    }

    public void setBy10(Float by10) {
        this.by10 = by10;
    }

    public LocalDateTime getBy11() {
        return by11;
    }

    public void setBy11(LocalDateTime by11) {
        this.by11 = by11;
    }

    public String getSffs() {
        return sffs;
    }

    public void setSffs(String sffs) {
        this.sffs = sffs;
    }

    public String getBy12() {
        return by12;
    }

    public void setBy12(String by12) {
        this.by12 = by12;
    }

    public String getBy13() {
        return by13;
    }

    public void setBy13(String by13) {
        this.by13 = by13;
    }

    public String getBy14() {
        return by14;
    }

    public void setBy14(String by14) {
        this.by14 = by14;
    }

    public String getBy15() {
        return by15;
    }

    public void setBy15(String by15) {
        this.by15 = by15;
    }

    public String getBy16() {
        return by16;
    }

    public void setBy16(String by16) {
        this.by16 = by16;
    }

    public String getBy17() {
        return by17;
    }

    public void setBy17(String by17) {
        this.by17 = by17;
    }

    public String getBy18() {
        return by18;
    }

    public void setBy18(String by18) {
        this.by18 = by18;
    }

    public Float getBy19() {
        return by19;
    }

    public void setBy19(Float by19) {
        this.by19 = by19;
    }

    public Float getBy20() {
        return by20;
    }

    public void setBy20(Float by20) {
        this.by20 = by20;
    }

    public String getOrder_id() {
        return order_id;
    }

    public void setOrder_id(String order_id) {
        this.order_id = order_id;
    }

//    public static void updateMoney() {
//        AppDatabase db = AppDatabase.getDatabase();
//
//        Wmlsbjb wmlsbjb = db.wmlsbjbDao().findOne();
//        if (wmlsbjb != null ) {
//            List<Wmlsb> wmlsbList = db.wmlsbDao().findByWmdbh(wmlsbjb.getWmdbh());
//            if (wmlsbList.size() == 0) {
//
//            }
//        }
//    }

    ///////////////////////////////
    ///////////////////////////////
    ///////////////////////////////
    ///////////////////////////////
    ///////////////////////////////

    /**
     * @param wmdbh 单据编号
     * @param yhbh  当前用户名称
     * @param zh    桌号
     * @param sfyjz 是否已结账（0未结账 1已结账）
     * @param jsj   计算机名
     * @param jcrs  就餐人数
     * @param ys    总计金额
     * @param by12  1开台 2点餐 默认1
     * @param jcfs  来客类型
     */
    public Wmlsbjb(String wmdbh, String yhbh, String zh, String sfyjz,
                   String jsj, String jcrs, float ys, String by12, String jcfs) {
        this.wmdbh = wmdbh;
        this.xtbz = "1";
        this.yhbh = yhbh;
        this.zh = zh;
//        this.jysj = jysj;
        this.sfyjz = sfyjz;
        this.jsj = jsj;
//        this.jcrs = jcrs;
        this.ys = ys;
        this.by12 = by12;
        this.jcfs = jcfs;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj != null && obj instanceof Wmlsbjb) {
            Wmlsbjb w = (Wmlsbjb) obj;
            return Objects.equals(this.wmdbh, w.wmdbh)
                    && Objects.equals(this.xtbz, w.xtbz)
                    && Objects.equals(this.yhbh, w.yhbh)
                    && Objects.equals(this.zh, w.zh)
                    && Objects.equals(this.ys, w.ys)
                    && Objects.equals(this.jysj, w.jysj)
                    && Objects.equals(this.sfyjz, w.sfyjz)
                    && Objects.equals(this.ysje, w.ysje)
                    && Objects.equals(this.hykh, w.hykh)
                    && Objects.equals(this.jsj, w.jsj)
                    && Objects.equals(this.qbdb, w.qbdb)
                    && Objects.equals(this.jcrs, w.jcrs)
                    && Objects.equals(this.zk, w.zk)
                    && Objects.equals(this.zr, w.zr)
                    && Objects.equals(this.bcwnjs, w.bcwnjs)
                    && Objects.equals(this.ss, w.ss)
                    && Objects.equals(this.hykdj, w.hykdj)
                    && Objects.equals(this.zkfs, w.zkfs)
                    && Objects.equals(this.jcfs, w.jcfs)
                    && Objects.equals(this.by1, w.by1)
                    && Objects.equals(this.by2, w.by2)
                    && Objects.equals(this.by3, w.by3)
                    && Objects.equals(this.by4, w.by4)
                    && Objects.equals(this.by5, w.by5)
                    && Objects.equals(this.jzbz, w.jzbz)
                    && Objects.equals(this.jskssj, w.jskssj)
                    && Objects.equals(this.jsjssj, w.jsjssj)
                    && Objects.equals(this.djlsh, w.djlsh)
                    && Objects.equals(this.by6, w.by6)
                    && Objects.equals(this.by7, w.by8)
                    && Objects.equals(this.by8, w.by8)
                    && Objects.equals(this.by9, w.by9)
                    && Objects.equals(this.by10, w.by10)
                    && Objects.equals(this.by11, w.by11)
                    && Objects.equals(this.sffs, w.sffs)
                    && Objects.equals(this.by12, w.by12)
                    && Objects.equals(this.by13, w.by13)
                    && Objects.equals(this.by14, w.by14)
                    && Objects.equals(this.by15, w.by15)
                    && Objects.equals(this.by16, w.by16)
                    && Objects.equals(this.by17, w.by17)
                    && Objects.equals(this.by18, w.by18)
                    && Objects.equals(this.by19, w.by19)
                    && Objects.equals(this.by20, w.by20)
                    && Objects.equals(this.order_id, w.order_id);
        } else {
            return super.equals(obj);
        }
    }

    /**
     * 例子:
     * INSERT INTO GSCYDB.dbo.WMLSBJB (WMDBH, XTBZ, YHBH, ZH, YS, JYSJ, SFYJZ, YSJE, HYKH, JSJ, QBDB, JCRS, ZK, ZR, BCWNJS, SS, HYKDJ, ZKFS, jcfs, by1, by2, by3, by4, by5, JZBZ, JSKSSJ, JSJSSJ, DJLSH, BY6, BY7, BY8, BY9, BY10, BY11, SFFS, BY12, BY13, BY14, BY15, BY16, BY17, BY18, BY19, BY20)
     * VALUES ('ZYB20170221140319921', '1', '店长', '101,', 10.00, '2017-02-21 14:03:24.000', '0', null, null, 'ZYB', null, 1, null, null, null, null, null, null, '堂食', '备注', '329', null, null, null, null, '2017-02-21 14:03:19.000', null, null, '', null, null, null, null, null, '', '2', null, null, null, null, null, null, null, null);
     */
    public String toInsertString() {
        return "INSERT INTO WMLSBJB (WMDBH,           XTBZ,           YHBH,           ZH,           YS,     JYSJ,           SFYJZ,      YSJE, HYKH,      JSJ,      QBDB,     JCRS,     ZK,   ZR,   BCWNJS, SS,   HYKDJ, ZKFS,      jcfs,     by1,by2, by3,  by4,  by5,  JZBZ,       JSKSSJ,    JSJSSJ, DJLSH, BY6, BY7,  BY8,  BY9,  BY10, BY11, SFFS,    BY12,      BY13, BY14, BY15, BY16, BY17, BY18, BY19, BY20) " +
                "       VALUES ('" + wmdbh + "', '" + xtbz + "', '" + yhbh + "', '" + zh + ",', " + ys + ", GETDATE(), '" + sfyjz + "', " + ysje + " , null, '" + jsj + "', null, " + jcrs + ", " + zk + ", " + ss + ", null,   null, null,  null, '" + jcfs + "', '', '', null, null, null, null, GETDATE(), null,  null,  '',  null, null, null, null, null, '', '" + by12 + "', null, null, null, null, null, null, null, null)|";
    }

    public static String toQuerySql(String wmdbh) {
        return String.format(Locale.CHINA, "SELECT wmdbh, xtbz, yhbh, zh, ys, jysj, sfyjz, " +
                "ysje, hykh, jsj, qbdb, jcrs, zk, zr, bcwnjs, ss, hykdj, zkfs, jcfs, by1, by2, by3, " +
                "by4, by5, jzbz, jskssj, jsjssj, djlsh, by6, by7, by8, by9, by10, by11, sffs, by12, " +
                "by13, by14, by15, by16, by17, by18, by19, by20, order_id FROM WMLSBJB WHERE WMDBH = '%s'|", wmdbh);
    }
}
